package com.itheima.web.mapper.pms;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.vo.pms.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PmsProductMapper extends BaseMapper<Product> {
    @Insert("insert into pms_member_price (product_id, member_level_id, member_price, member_level_name) VALUES (#{productId} , #{memberLevelId} , #{memberPrice} , #{memberLevelName}) ")
    void addMemberPrice(MemberPrice memberPrice);

    @Insert("insert into cms_prefrence_area_product_relation (prefrence_area_id, product_id) values (#{prefrenceAreaId} , #{productId})")
    void addPrefrenceAreaProductRelation(PrefrenceAreaProductRelation prefrenceAreaProductRelation);

    @Insert("insert into pms_product_attribute_value (product_id, product_attribute_id, value) values (#{productId} , #{productAttributeId} , #{value})")
    void addProductAttributeValue(ProductAttributeValue productAttributeValue);

    @Insert("insert into pms_product_full_reduction (product_id, full_price, reduce_price) VALUES (#{productId} , #{fullPrice} , #{reducePrice}) ")
    void addProductFullReduction(ProductFullReduction productFullReduction);

    @Insert("insert into pms_product_ladder (product_id, count, discount, price) values (#{productId} , #{count} , #{discount} , #{price})")
    void addProductLadder(ProductLadder productLadder);

    @Insert("insert into cms_subject_product_relation (subject_id, product_id) VALUES (#{subjectId} , #{productId}) ")
    void addSubjectProductRelation(SubjectProductRelation subjectProductRelation);

    @Insert("insert into pms_sku_stock (product_id, sku_code, price, stock, low_stock, pic, sale, promotion_price, lock_stock, sp_data) " +
            "values (#{productId} , #{skuCode} , #{price} , #{stock} , #{lowStock} , #{pic} , #{sale} , #{promotionPrice} , #{lockStock} , #{spData})")
    void addSkuStock(SkuStock skuStock);

    @Insert("insert into pms_product_vertify_record (product_id, create_time, vertify_man, status, detail) values (#{id} , #{createTime} , #{vertifyMan} , #{status} , #{detail})")
    void addVertifyRecord(@Param("id") Long id, @Param("createTime") String createTime, @Param("vertifyMan") String vertifyMan, @Param("status") int status, @Param("detail") String detail);

    @Select("select * from pms_member_price where product_id = #{id}")
    List<MemberPrice> getMemberPrice(Long id);

    @Select("select * from cms_prefrence_area_product_relation where product_id = #{id}")
    List<PrefrenceAreaProductRelation> getPrefrenceAreaProductRelation(Long id);

    @Select("select * from pms_product_attribute_value where product_id = #{id}")
    List<ProductAttributeValue> getProductAttributeValue(Long id);

    @Select("select * from pms_product_full_reduction where product_id = #{id}")
    List<ProductFullReduction> getProductFullReduction(Long id);

    @Select("select * from pms_product_ladder where product_id = #{id}")
    List<ProductLadder> getProductLadderList(Long id);

    @Select("select * from pms_sku_stock where product_id = #{id}")
    List<SkuStock> getSkuStockList(Long id);

    @Select("select * from cms_subject_product_relation where product_id = #{id}")
    List<SubjectProductRelation> getSubjectProductRelationList(Long id);

    @Update("update pms_member_price set member_level_id = #{memberLevelId} , member_price = #{memberPrice} , member_level_name = #{memberLevelName} where product_id = #{productId}")
    void updateMemberPrice(MemberPrice memberPrice);

    @Update("update cms_prefrence_area_product_relation set prefrence_area_id = #{prefrenceAreaId} where product_id = #{productId}")
    void updatePrefrenceAreaProductRelation(PrefrenceAreaProductRelation areaProductRelation);

    @Update("update pms_product_attribute_value set product_attribute_id = #{productAttributeId} , value = #{value} where product_id = #{productId}")
    void updateProductAttributeValue(ProductAttributeValue attributeValue);

    @Update("update pms_product_full_reduction set full_price = #{fullPrice} , reduce_price = #{reducePrice} where product_id = #{productId}")
    void updateProductFullReduction(ProductFullReduction fullReduction);

    @Update("update pms_product_ladder set count = #{count} , discount = #{discount} , price = #{price} where product_id = #{productId}")
    void updateProductLadder(ProductLadder ladder);

    @Update("update pms_sku_stock set sku_code = #{skuCode} , price = #{price} , stock = #{stock} , low_stock = #{lowStock} , pic = #{pic} , sale = #{sale} , promotion_price = #{promotionPrice} , lock_stock = #{lockStock} , sp_data = #{spData} where product_id = #{productId}")
    void updateSkuStock(SkuStock skuStock);

    @Update("update cms_subject_product_relation set subject_id = #{subjectId} where product_id = #{productId}")
    void updateSubjectProductRelation(SubjectProductRelation subjectProductRelation);
}
